10 //Mouse Control Script using IR
11 //by vkapadia with much assistance from inio
12 //vkapadia@vkapadia.com
15 //To calibrate, run this program and put the Wiimote on a flat surface face-up.
16 //Then read the values in the debug line (next to the run button).
17 //Change these values until the debug line reads approx. all zeros.
30 var.deadzone = 5 //distance in pixels that you have to move the wiimote in
31 //order for it to register movement. Creates a "dead zone" around the pointer
32 //to make it easier to click. Higher = smoother but less accurate.
35 //cursor2.visible = true
37 //more options to be added later
40 //Point Wiimote = Move Mouse
42 //B-Button = Left Click
44 //A-Button = Right Click
45 //Plus and Minus = Control Volume
49 //If the pointer hits the edge of the screen, the Wiimote will rumble a bit.
51 //The LEDs attempt to emulate KITT's grill from Knight Rider
53 //***Do not edit anything below this line unless you know what you are doing.***
54 var.accx1 = wiimote1.RawForceX1 + var.xtrim1
55 var.accy1 = wiimote1.RawForceY1 + var.ytrim1
56 var.accz1 = wiimote1.RawForceZ1 + var.ztrim1
58 if wiimote1.dot1vis and wiimote1.dot2vis then
60 if var.accy1 > -7 then
62 elseif var.accy1 > -45 then
72 if var.leftpoint1 = 0 then
73 if var.orientation1 = 0 then
74 if wiimote1.dot1x < wiimote1.dot2x then
80 if var.orientation1 = 1 then
81 if wiimote1.dot1y > wiimote1.dot2y then
87 if var.orientation1 = 2 then
88 if wiimote1.dot1x > wiimote1.dot2x then
94 if var.orientation = 3 then
95 if wiimote1.dot1y < wiimote1.dot2y then
103 if var.leftpoint1 = 1 then
104 var.fix1x1 = wiimote1.dot1x
105 var.fix1y1 = wiimote1.dot1y
106 var.fix2x1 = wiimote1.dot2x
107 var.fix2y1 = wiimote1.dot2y
109 var.fix1x1 = wiimote1.dot2x
110 var.fix1y1 = wiimote1.dot2y
111 var.fix2x1 = wiimote1.dot1x
112 var.fix2y1 = wiimote1.dot1y
115 var.dx1 = var.fix2x1 - var.fix1x1
116 var.dy1 = var.fix2y1 - var.fix1y1
117 var.cx1 = (var.fix1x1+var.fix2x1)/1024.0 - 1
118 var.cy1 = (var.fix1y1+var.fix2y1)/1024.0 - .75
120 var.d1 = sqrt(var.dx1*var.dx1+var.dy1*var.dy1)
122 var.dx1 = var.dx1 / var.d1
123 var.dy1 = var.dy1 / var.d1
125 var.ox1 = -var.dy1*var.cy1-var.dx1*var.cx1;
126 var.oy1 = -var.dx1*var.cy1+var.dy1*var.cx1;
128 var.ax1 = (var.ox1 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
129 var.ay1 = (-var.oy1* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
131 var.dx1 = var.ax1 - cursor2.posx
132 var.dy1 = var.ay1 - cursor2.posy
134 var.d1 = sqrt((var.dx1*var.dx1)+(var.dy1*var.dy1))
136 var.a1 = 180 / (200 + var.d1 * var.d1 * var.d1 * .001)
138 if var.d1 <= var.deadzone then var.a1 = 1
140 //debug = var.d + " " + var.a
142 var.finalx1 = cursor2.posx * var.a1 + var.ax1 * (1 - var.a1)
143 var.finaly1 = cursor2.posy * var.a1 + var.ay1 * (1 - var.a1)
146 cursor2.posx = smooth(var.finalx1,3,5)
147 cursor2.posy = smooth(var.finaly1,3,5)
155 var.xpos1 = var.finalx1
156 var.ypos1 = var.finaly1
157 ppjoy1.analog0 = ensuremaprange(var.xpos1,0,screen.desktopwidth* var.coeff,-1,1)
158 ppjoy1.analog1 = ensuremaprange(var.ypos1,0,screen.desktopheight* var.coeff,-1,1)
160 if wiimote1.B or wiimote1.A or wiimote1.Up or wiimote1.down or wiimote1.Left or wiimote1.Right == true
161 ppjoy1.digital0 = true
163 ppjoy1.digital0 = false
166 debug = var.accx1+ " " + var.accy1+ " " + var.accz1